var s=document.getElementById("header").src;
function GetQueryString(_parameter){
	var sValue=s.match(new RegExp("[?&]"+_parameter+"=([^&]*)(&?)","i"));
	if(sValue?sValue[1]:sValue==null)
		return sValue?sValue[1]:sValue;
};
function breakout_of_frame() {
	if (top.location != document.location) {
		top.location.href = document.location.href;
	}
};
document.write('<link href="'+GetQueryString("head")+'/js/lib/layui/css/layui.css" rel="stylesheet" type="text/css" />');
document.write('<link href="'+GetQueryString("head")+'js/static/h-ui/css/H-ui.min.css" rel="stylesheet" type="text/css" />');
document.write('<link href="'+GetQueryString("head")+'js/static/h-ui.admin/css/H-ui.admin.css" rel="stylesheet" type="text/css" />');
document.write('<link href="'+GetQueryString("head")+'js/lib/Hui-iconfont/1.0.8/iconfont.css" rel="stylesheet" type="text/css" />');
document.write('<link id="skin" href="'+GetQueryString("head")+'js/static/h-ui.admin/skin/default/skin.css" rel="stylesheet" type="text/css" />');
document.write('<link href="'+GetQueryString("head")+'js/static/h-ui.admin/css/style.css" rel="stylesheet" type="text/css" />');
document.write('<link href="'+GetQueryString("head")+'css/search.css" rel="stylesheet" type="text/css" />');
//document.write('<link href="'+GetQueryString("head")+'js/lib/layer/3.1/theme/default/layer.css" rel="stylesheet" type="text/css" />');
//document.write('<link href="'+GetQueryString("head")+'js/lib/zTree/v3/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />');
//document.write('<script type="text/javascript" src="'+GetQueryString("head")+'js/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>');
document.write('<script type="text/javascript" src="'+GetQueryString("head")+'js/lib/jquery/1.9.1/jquery.min.js"></script>');
document.write('<script type="text/javascript" src="'+GetQueryString("head")+'js/lib/layer/2.4/layer.js"></script>');
document.write('<script type="text/javascript" src="'+GetQueryString("head")+'js/lib/laydate/laydate.js"></script>');
document.write('<script type="text/javascript" src="'+GetQueryString("head")+'js/static/h-ui/js/H-ui.min.js"></script>');
document.write('<script type="text/javascript" src="'+GetQueryString("head")+'js/static/h-ui.admin/js/H-ui.admin.js"></script>');
//document.write('<script type="text/javascript" src="'+GetQueryString("head")+'js/lib/jquery-form.js"></script>');

//document.write('<script type="text/javascript" src="'+GetQueryString("head")+'js/lib/laypage/1.2/laypage.js"></script>');
//document.write('<script type="text/javascript" src="'+GetQueryString("head")+'js/lib/My97DatePicker/4.8/WdatePicker.js"></script>');
document.write('<script type="text/javascript" src="'+GetQueryString("head")+'js/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>');
document.write('<script type="text/javascript" src="'+GetQueryString("head")+'js/lib/jquery.validation/1.14.0/jquery.validate.js"></script>');
document.write('<script type="text/javascript" src="'+GetQueryString("head")+'js/lib/jquery.validation/1.14.0/validate-methods.js"></script>');
document.write('<script type="text/javascript" src="'+GetQueryString("head")+'js/lib/jquery.validation/1.14.0/messages_zh.js"></script>');
document.write('<script type="text/javascript" src="'+GetQueryString("head")+'js/lib/layui/layui.js"></script>');

function MyDataTable(options){
	if(!options.id){
		layer.msg("id必须");
		return;
	}
	if(!options.pageUrl){
		layer.msg("pageUrl必须");
		return;
	}
	if(!options.columns){
		layer.msg("columns必须");
		return;
	}
	var columns=options.columns;
	$.each(columns,function(i,item){
		if(item.render==undefined){
			item.render= function (data, type, full) {
				if (data!=undefined) {
					return data;
				}
				return "";
			}
		}
	});
	var baseOptions={
		  "processing": true,
	      "serverSide": true,
	      "iDisplayLength" :10,
	      "bRetrieve": true,
	      "aLengthMenu" : [10,20,50,100],
	      "bPaginate": true, //开关，是否显示分页器
	      "bLengthChange": true, //改变每页显示数据数量
	      "bFilter": false, //过滤功能
	      "bSort": true, //排序功能
	      "bInfo": true,//页脚信息
	      "bAutoWidth": false,//自动宽度
	      "ajax": function (data, callback, settings){
	        	  //封装请求参数
	        	  layer.load();
	        	  var param = {};
	        	  if(options.param){
	        		  param = $.extend(param,options.param());
	        	  }
	        	 var columns=settings.aoColumns;
	        	 var orders=data.order;
	        	 for(var i=0;i<orders.length;i++){
	        		 var o=orders[i];
	        		 var columnIndex=o.column;
	        		 var col=columns[columnIndex];
	        		 var columnName=col.data;
	        		 var sort=o.dir;
	        		 param.sort=columnName;
	        		 param.order=sort;
	        	 }
	        	  param.size = data.length;//页面显示记录条数，在页面显示每页显示多少项的时候
	        	  param.current = parseInt((data.start / data.length)+1);//当前页码
		       	 	$.ajax({
			      		url:options.pageUrl,
			      		type:'get',
			      		datatype:'json',
			      		data:param,
			      		success:function(result){
			      		  //封装返回数据
			      		    var returnData = {};
			      		    returnData.recordsTotal = result.total;//返回数据全部记录
			      		    returnData.recordsFiltered = result.total;//后台不实现过滤功能，每次查询均视作全部结果
			      		    returnData.data = result.records;//返回的数据列表
			      		    callback(returnData);
			      		    layer.closeAll();
			      		    if(options.success){
			      		    	options.success();
			      		    }
			      		}
		       	 	});
	          }
	};
      var o3 = $.extend(baseOptions,options);
      var dataTable=$('#'+options.id).dataTable(o3).api();
	  return dataTable;
};

/**
 * 导出
 */
function baseExport(exportUrl)
{
    var $body = $(document.body),
        $form = $("<form id='hiddenForm' action=\'"+exportUrl+"\'></form>"),
        input,obj={};
    $(".inputClass input,select").each(function(){
        var id=$(this).attr("id");
        obj[id] = $(this).val();
    });
    $.each(obj,function(key,value){
        input = $("<input type='hidden'>");
        input.attr({"name":key});
        input.val(value);
        $form.append(input);
    });
    $form.appendTo($body);
    $form.submit();
    $form.remove();
};
